package com.fyzk.activity.prize;

import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.fyzk.bean.JZPrizeInfo;
import com.tyjc.lottery.R;

import java.util.List;

/**
 * 竞彩足球开奖列表
 */
public class JZPrizeAdapter extends BaseAdapter{
	
	private int tv_saiGuo;
	private Context context;
	protected List<JZPrizeInfo> list_infor;
	protected LayoutInflater myInflater;
	protected Resources myResources;
	
	
	protected JZPrizeAdapter(Context context, List<JZPrizeInfo> list_infor){
		this.context = context;
		this.list_infor = list_infor;
		this.myInflater = LayoutInflater.from(context);
		this.myResources = context.getResources();
	}
	
	@Override
	public int getCount() {
		
		return list_infor.size();
	}

	@Override
	public Object getItem(int arg0) {
		
		return list_infor.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		JZPrizeInfo infor = list_infor.get(position);
		
		convertView = myInflater.inflate(R.layout.kaijiang_lishi_jc, null);
		ViewHolder holder = new ViewHolder();
		
		holder.saiShi = (TextView)convertView.findViewById(R.id.kjls_jc_saiShi);
		holder.id = (TextView)convertView.findViewById(R.id.kjls_jc_id);
		holder.time = (TextView)convertView.findViewById(R.id.kjls_jc_time);
		holder.zhu = (TextView)convertView.findViewById(R.id.kjls_jc_zhu);
		holder.ke = (TextView)convertView.findViewById(R.id.kjls_jc_ke);
		holder.biFen = (TextView)convertView.findViewById(R.id.kjls_jc_biFen);
		
		holder.spf = (TextView)convertView.findViewById(R.id.kjls_jc_spf);
		holder.rspf = (TextView)convertView.findViewById(R.id.kjls_jc_rspf);
		holder.bf = (TextView)convertView.findViewById(R.id.kjls_jc_bf);
		holder.zjq = (TextView)convertView.findViewById(R.id.kjls_jc_zjq);
		holder.bqc = (TextView)convertView.findViewById(R.id.kjls_jc_bqc);
		
		convertView.setTag(holder);
		
		holder.saiShi.setText(infor.getMatchName());
		holder.id.setText(infor.getMatchNum());
		holder.time.setText(infor.getOfficialWeekDay());
		holder.zhu.setText(infor.getHomeTeam());
		holder.ke.setText(infor.getAwayTeam());
		holder.biFen.setText(infor.getBfResult());
		
		String rang = infor.getHandicap();
		holder.spf.setText(infor.getSpfResult());
		holder.rspf.setText("("+rang+")"+(infor.getRqSpfResult() != null ? infor.getRqSpfResult() : ""));
		holder.bf.setText(infor.getBfResult());
		holder.zjq.setText((infor.getJqsResult() != null ? infor.getJqsResult() : "-")+"球");
		holder.bqc.setText(infor.getBqcResult());
		
		
		if (infor != null && infor.getSpfResult() != null) {
			if (infor.getSpfResult().equals("胜")) {
				tv_saiGuo = myResources.getColor(R.color.top_bg);
			}else if (infor.getSpfResult().equals("平")) {
				tv_saiGuo = myResources.getColor(R.color.kaijiang_jc_tv_ping);
			}else{
				tv_saiGuo = myResources.getColor(R.color.kaijiang_jc_tv_fu);
			}
		}

//		holder.ll_saiGuo.setBackgroundColor(bg_saiGuo);
//		holder.saiGuo.setTextColor(tv_saiGuo);
		holder.biFen.setTextColor(tv_saiGuo);
		
		return convertView;
	}
	public void setList_infor(List<JZPrizeInfo> list_infor) {
		this.list_infor = list_infor;
		this.notifyDataSetChanged();
	}

	class ViewHolder {
		TextView saiShi;
		TextView id;
		TextView time;
		TextView zhu;
		TextView ke;
		TextView saiGuo;
		TextView biFen;
		
		TextView spf;
		TextView rspf;
		TextView bf;
		TextView zjq;
		TextView bqc;

	}
	

}
